package com.tiancheng.trade.merchant.util;

import com.tiancheng.trade.commom.core.enums.PaymentChannelEnum;
import com.tiancheng.trade.merchant.enums.CostTypeEnum;
import com.tiancheng.trade.merchant.enums.MerchantAccountTypeEnum;
import com.tiancheng.trade.merchant.enums.MerchantScenarioEnum;
import com.tiancheng.trade.merchant.vo.KeyValueVO;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class DictUtil {

    private static final String MERCHANT_ACCOUNT_TYPE_ENUM = "merchantAccountType";
    private static final String MERCHANT_PAYMENT_CHANNEL_ENUM = "merchantPaymentChannel";
    private static final String MERCHANT_SCENARIO_ENUM = "merchantScenario";
    private static final String COST_TYPE_ENUM = "costType";

    private static final Map<String, List<KeyValueVO>> map = new HashMap<>();

    public static Map<String, List<KeyValueVO>> getDict() {
        return map;
    }

    public static List<KeyValueVO> getDict(String dictType) {
        return map.get(dictType);
    }

    static {
        List<KeyValueVO> settlementClearRuleEnum = Arrays.stream(PaymentChannelEnum.values()).map(e -> {
            KeyValueVO KeyValueVO = new KeyValueVO();
            KeyValueVO.setKey(e.getCode());
            KeyValueVO.setValue(e.getDesc());
            return KeyValueVO;
        }).collect(Collectors.toList());
        map.put(DictUtil.MERCHANT_PAYMENT_CHANNEL_ENUM, settlementClearRuleEnum);

        List<KeyValueVO> settlementCycleModeEnum = Arrays.stream(MerchantAccountTypeEnum.values()).map(e -> {
            KeyValueVO KeyValueVO = new KeyValueVO();
            KeyValueVO.setKey(e.getCode());
            KeyValueVO.setValue(e.getDesc());
            return KeyValueVO;
        }).collect(Collectors.toList());
        map.put(DictUtil.MERCHANT_ACCOUNT_TYPE_ENUM, settlementCycleModeEnum);

        List<KeyValueVO> settlementRuleTypeEnum = Arrays.stream(MerchantScenarioEnum.values()).map(e -> {
            KeyValueVO KeyValueVO = new KeyValueVO();
            KeyValueVO.setKey(e.getCode());
            KeyValueVO.setValue(e.getDesc());
            return KeyValueVO;
        }).collect(Collectors.toList());
        map.put(DictUtil.MERCHANT_SCENARIO_ENUM, settlementRuleTypeEnum);

        List<KeyValueVO> costTypeEnum = Arrays.stream(CostTypeEnum.values()).map(e -> {
            KeyValueVO KeyValueVO = new KeyValueVO();
            KeyValueVO.setKey(e.getCode());
            KeyValueVO.setValue(e.getDesc());
            return KeyValueVO;
        }).collect(Collectors.toList());
        map.put(DictUtil.COST_TYPE_ENUM, costTypeEnum);

    }
}
